package com.litong.rms.dao.impl;

import java.util.List;

import com.litong.rms.bean.Function;
import com.litong.rms.dao.FunctionDao;

public class FunctionDaoImpl extends BaseDaoImpl implements FunctionDao{

	/**
	 * 
	 */
	private static final long serialVersionUID = -9034688775344110348L;

	public void addFunction(Function func) {
		save(func);
		
	}

	public void deleteFunction(Function func) {
		
		delete(func);
		
	}

	public Function findFunction(Function func) {
		String functionName = func.getFunctionName().trim();
		String queryString = "from Function where functionName = ?";
		List<Function> functionList = find(queryString,functionName);
		if(functionList!=null&&!functionList.isEmpty()){
			return functionList.get(0);
		}
		return null;
	}

	@SuppressWarnings("unchecked")
	public  List<Function> getFunctionList() {
		String queryString = "from Function";
		List<Function> functionList = getEntityList(queryString);
		if(functionList!=null&&!functionList.isEmpty()){
			return  functionList;
		}
		return null;
	}

	public void updateFunction(Function func) {
		this.saveOrUpdate(func);
	}

	public Function findById(int functionId) {
		String queryString = "from Function where functionId = ?";
		int value = functionId;
		List<Function> functionList = this.find(queryString, value);
		if(functionList!=null&&!functionList.isEmpty()){
			Function function = functionList.get(0);
			return function;
		}else{
			return null;
		}	
	}


}
